<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
            <title>Operation</title>
            
            <link href="Style.css" rel="stylesheet" type="text/css" />
            <script src="jquery-1.7.2.min.js" type="text/javascript"></script>
            <script src="Ponto.js" type="text/javascript"></script>
            <script src="Common.js" type="text/javascript"></script>
            <script type="text/javascript">
                
                var $delivery_id;
                var $status;
                var $statusText = ["装货完成", "到达", "卸货完成"];
                
                $(document).ready(function(){
                                  $("#detailButton").bind("click", function(){
                                                          window.location.href = "Detail.html";
                                                          });
                                  
                                  $("#statusButton").bind("click", function(){
                                                          if ($status > 2){
                                                          return;
                                                          }
                                                          setStatus($delivery_id, $status);
                                                          $status = parseInt($status) + 1;
                                                          $("#statusButton").text($statusText[$status]);
                                                          });
                                  
                                  $("#errorDiv").html("获取数据中...");
                                  $.ajax({
                                         url: "http://testvms.yqphh.com/purchase/delivery/123",
                                         data: {
                                         },
                                         type: "get",
                                         dataType: "json",
                                         
                                         error: function() {
                                         $("#errorDiv").html("获取数据失败");
                                         },
                                         
                                         success: function(data) {
                                         if (data.result == "ok"){
                                         $("#errorDiv").html("");
                                         
                                         localStorage["data"] = JSON.stringify(data);
                                         
                                         $delivery_id = data.delivery_id;
                                         $status = data.status;
                                         $("#statusButton").text($statusText[data.status]);
                                         $("#warehousePhoneA").text("仓库电话：" + data.warehouse_phone_number);
                                         $("#buyerPhoneA").text("采购电话：" + data.buyer_phone_number);
                                         $("#warehousePhoneButton").bind("click", function(){
                                                                         toCall(data.warehouse_phone_number);
                                                                         });
                                         $("#buyerPhoneButton").bind("click", function(){
                                                                     toCall(data.buyer_phone_number);
                                                                     });
                                         }
                                         else{
                                         if (isRelogin(data.error_code)){
                                         return;
                                         }
                                         $("#errorDiv").html("error_code: " + data.error_code + "<br/>error_info: " + data.error_info);
                                         }
                                         }
                                         });
                                  });
                </script>
            
            <style type="text/css">
                table{
                    height: 300px;
                }
            
            #detailButton{
                background: #3498DB;
                height: 40px;
            }
            
            #statusButton{
                font-size: 50px;
                background: #E74C3C;
                height: 200px;
            }
            
            #warehousePhoneButton, #buyerPhoneButton{
                background: #2ECC71;
                height: 40px;
            }
            </style>
            </head>
    <body>
        <table cellpadding="0" cellspacing="0">
            <tr>
                <td>
                    <button id="detailButton">详情</button>
                </td>
            </tr>
            <tr>
                <td>
<!--                    装货完成/到达/卸货完成-->
                    <button id="statusButton"></button>
                </td>
            </tr>
            <tr>
                <td>
                    <button id="warehousePhoneButton"><a id="warehousePhoneA" href="#">仓库电话</a></button>
                </td>
            </tr>
            <tr>
                <td>
                    <button id="buyerPhoneButton"><a id="buyerPhoneA" href="#">采购电话</a></button>
                </td>
            </tr>
            <tr>
                <td>
                    <div id="errorDiv"></div>
                </td>
            </tr>
        </table>
    </body>
</html>